<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/18
 * Time: 9:52
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class GoodsCategory extends Model
{
    public static $TOP_CATE = 1;



    protected $table = 'goods_categories';
    public $timestamps = false;

    protected $fillable = [
        'goods_name', 'sort_order', 'parent_id'
    ];

    public function getGoodsPath()
    {
        if (!empty($this->parent)) {
            return $this->parent->getGoodsPath().'>>'.$this->goods_name;
        } else {
            return $this->goods_name;
        }
    }

    public function parent()
    {
        return $this->belongsTo('App\GoodsCategory', 'parent_id');
    }
}